﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PRET.ReportControlLib.Controls
{
    public partial class TeamAttendanceMonth : UserControl
    {
        public event ModifyTeamHoursEventHandle modifyHoursEvent;

        public TeamAttendanceMonth()
        {
            InitializeComponent();
        }

        public double SetAHours
        {
            set { this.AHoursTextBox.Text = value.ToString(); }
        }
        public double SetBHours
        {
            set { this.BHoursTextBox.Text = value.ToString(); }
        }
        public double SetCHours
        {
            set { this.CHoursTextBox.Text = value.ToString(); }
        }
        public double SetDHours
        {
            set { this.DHoursTextBox.Text = value.ToString(); }
        }
        public double SetEHours
        {
            set { this.EHoursTextBox.Text = value.ToString(); }
        }
        public double SetFHours
        {
            set { this.FHoursTextBox.Text = value.ToString(); }
        }

        private void modifyBtn_Click(object sender, EventArgs e)
        {
            if (!VerifyHours())
            {
                string msg = "请输入有效的班组休整小时";
                MessageBox.Show(msg, "输入知无效", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (modifyHoursEvent != null)
            {
                ModifyTeamHoursEventArgs eventArg = new ModifyTeamHoursEventArgs();
                eventArg.AHours = double.Parse(this.AHoursTextBox.Text);
                eventArg.BHours = double.Parse(this.BHoursTextBox.Text);
                eventArg.CHours = double.Parse(this.CHoursTextBox.Text);
                eventArg.DHours = double.Parse(this.DHoursTextBox.Text);
                eventArg.EHours = double.Parse(this.EHoursTextBox.Text);
                eventArg.FHours = double.Parse(this.FHoursTextBox.Text);
                modifyHoursEvent(this, eventArg);

                this.AHoursTextBox.Text = "";
                this.BHoursTextBox.Text = "";
                this.CHoursTextBox.Text = "";
                this.DHoursTextBox.Text = "";
                this.EHoursTextBox.Text = "";
                this.FHoursTextBox.Text = "";
            }
        }

        private bool VerifyHours()
        {
            double hours = 0;
            if (!double.TryParse(this.AHoursTextBox.Text, out hours))
                return false;
            if (!double.TryParse(this.BHoursTextBox.Text, out hours))
                return false;
            if (!double.TryParse(this.CHoursTextBox.Text, out hours))
                return false;
            if (!double.TryParse(this.DHoursTextBox.Text, out hours))
                return false;
            if (!double.TryParse(this.EHoursTextBox.Text, out hours))
                return false;
            if (!double.TryParse(this.FHoursTextBox.Text, out hours))
                return false;
            return true;
        }

        public void EnableControls(bool sign)
        {
            this.AHoursTextBox.Enabled = sign;
            this.BHoursTextBox.Enabled = sign;
            this.CHoursTextBox.Enabled = sign;
            this.DHoursTextBox.Enabled = sign;
            this.EHoursTextBox.Enabled = sign;
            this.FHoursTextBox.Enabled = sign;
            this.modifyBtn.Enabled = sign;
        }
    }

    public delegate void ModifyTeamHoursEventHandle(object sender, ModifyTeamHoursEventArgs args);

    public class ModifyTeamHoursEventArgs : EventArgs
    {
        public ModifyTeamHoursEventArgs()
        {
        }
        private double ahours = 0;
        private double bhours = 0;
        private double chours = 0;
        private double dhours = 0;
        private double ehours = 0;
        private double fhours = 0;

        public double AHours
        {
            get { return ahours; }
            set { ahours = value; }
        }
        public double BHours
        {
            get { return bhours; }
            set { bhours = value; }
        }
        public double CHours
        {
            get { return chours; }
            set { chours = value; }
        }
        public double DHours
        {
            get { return dhours; }
            set { dhours = value; }
        }
        public double EHours
        {
            get { return ehours; }
            set { ehours = value; }
        }
        public double FHours
        {
            get { return fhours; }
            set { fhours = value; }
        }
    }
}
